import java.io.*;

public class Test6 {
    public static void main(String[] args) {
        String fileName = "D:\\Java\\data1.dat";

        int value0 = 255;
        int value1 = 0;
        int value2 = -1;

        try {
            DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName));//打开文件写数据，若文件不存在则创建新文件，可覆盖原文件
            out.writeInt(value0);
            out.writeInt(value1);
            out.writeInt(value2);
            out.close();
        } catch (IOException e) {
            System.out.println("Program writing " + fileName);
        }

        try {
            DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(fileName)));
            int sum = 0;
            sum += in.readInt();
            sum += in.readInt();
            sum += in.readInt();
            System.out.println("sum = " + sum);
            in.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
